package com.api.shopapi.mapper;


import com.api.shopapi.entity.UserLonLat;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
@Mapper
public interface UserLonLatMapper {

    @Insert("insert into user_lonlat (UserLonLatCode,UserCode,Lon,Lat,CreateTime) " +
            "values(#{userLonLat.UserLonLatCode},#{userLonLat.UserCode},#{userLonLat.Lon}," +
            "#{userLonLat.Lat},#{userLonLat.CreateTime})")
    int insert(@Param("userLonLat") UserLonLat userLonLat);

    @Update("update user_lonlat set UserCode=#{userLonLat.UserCode},Lon=#{userLonLat.Lon},Lat=#{userLonLat.Lat} " +
            "where UserLonLatCode=#{userLonLat.UserLonLatCode}")
    int update(@Param("userLonLat") UserLonLat userLonLat);

    @Delete("delete from user_lonlat where UserLonLatCode=#{userLonLatCode}")
    int delete(@Param("userLonLatCode")String userLonLatCode);

    @Select("select * from user_lonlat where UserLonLatCode=#{userLonLatCode} limit 1")
    UserLonLat getByUserLonLatCode(@Param("userLonLatCode")String userLonLatCode);

    @Select("select * from user_lonlat where UserCode=#{userCode} limit 1")
    UserLonLat getByUserCode(@Param("userCode")String userCode);

    @Select("select * from user_lonlat order by CreateTime desc")
    List<UserLonLat> getList();



    @Select("<script>" +
            "select * from user_lonlat " +
            " where" +
            " createTime between #{startTime} and #{endTime}" +
            " and userCode = #{userCode} " +
            " order by createTime desc" +
            "</script>")
    List<UserLonLat> getListBySpanTime(@Param("userCode") String userCode,
                                       @Param("startTime") Date startTime,
                                       @Param("endTime") Date endTime);


    @Select("<script>" +
            "select * from user_lonlat " +
            " where" +
            " createTime > #{lastTime}" +
            " and userCode = #{userCode} " +
            " order by createTime desc" +
            "</script>")
    List<UserLonLat> getListAfterTime(@Param("userCode") String userCode,
                                       @Param("lastTime") Date lastTime);


}
